package tech.lq0.dreamaticvoyage.gui.slot;

import net.minecraft.network.chat.Component;

/**
 * Code based on @GoryMoon's Chargers
 */
public abstract class ContainerComponentDataSlot {

    private Component prevValue;

    public ContainerComponentDataSlot() {
    }

    public static ContainerComponentDataSlot forContainer(final ContainerComponentData data, final int index) {
        return new ContainerComponentDataSlot() {
            public Component get() {
                return data.get(index);
            }

            public void set(Component value) {
                data.set(index, value);
            }
        };
    }

    public abstract Component get();

    public abstract void set(Component value);

    public boolean checkAndClearUpdateFlag() {
        Component tmp = this.get();
        boolean changed = tmp != this.prevValue;
        this.prevValue = tmp;
        return changed;
    }
}
